package com.hns.can.report.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.master.entity.AppCarMaintenInfoEntity;
import com.hns.can.master.entity.BaseCarDrvRelEntity;
import com.hns.can.master.entity.CommEnerConsStatInfoEntity;
import com.hns.can.report.entity.BiCarIdxInfoEntity;
import com.hns.can.report.vo.CarAnaCarVo;
import com.hns.can.report.vo.DrivingRecordAnalysisVo;
import com.hns.can.report.vo.DrvAnaDrvVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;

/**
 * 车辆画像
 * @author:lan
 * @email:763836737@qq.com
 * @version Revision 2.0.0
 */
@Service
public class CarAnaService extends CommonService {
    
	/**
	 * 填充代码描述
	 */
    @Autowired
    private FillCodeDscValue codeDscValue;
    
   /**
    * 获取车辆信息
    * @param carId
    * @return
    * @throws Exception
    * @author:lan
    * @email:763836737@qq.com
    */
    @SuppressWarnings({"unchecked"})
    public CarAnaCarVo getCarAnaCarInfo(String carId) throws Exception {
          List<CarAnaCarVo> list = PubUtil.convertListMapToObject(
             		this.sqlMapDao.selectList("carAna.getCarAnaCarInfo", carId), CarAnaCarVo.class);
          Map<String,String> map = new HashMap<String,String>();
          map.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);   
          map.put("lineCode", "lineCode");   
          FillParamsVo vo = new FillParamsVo("lineId", map);
          Map<String,String> map2 = new HashMap<String,String>();
          map2.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);   
          FillParamsVo vo2 = new FillParamsVo("organId", map2);
          codeDscValue.fillInfoValue(list, new String[] {GlobalConst.CACHE_KEY_BASE_LINE_INFO,GlobalConst.CACHE_KEY_BASE_ORGAN},vo,vo2);
          return list.get(0);
    }
    
    /**
     * 根据线路id求线路信息
     * @param lineId
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     @Transactional
     public BaseEntity getCarDrvRel(String carId) throws Exception {
          List<BaseCarDrvRelEntity> list = PubUtil.convertListMapToObject(
              this.sqlMapDao.selectList("carAna.getCarDrvRel", carId), BaseCarDrvRelEntity.class);
          if(list!=null){
              Map<String,String> map = new HashMap<String,String>();
              map.put("drvName",  GlobalConst.DEFAULT_CACHE_VALUE);   
              FillParamsVo vo = new FillParamsVo("drvId", map);
              codeDscValue.fillInfoValue(list, new String[] {GlobalConst.CACHE_KEY_BASE_DRV_INFO},vo);
              return list.get(0) ;
          }else{
            return null;
          }
     }
    
    /**
     * 查询故障、线路、排名
     * @param vo
     * @return
     * @throws Exception
     * @author:lan
     * @email:763836737@qq.com
     */
     @SuppressWarnings("unchecked")
     public List<BiCarIdxInfoEntity> getCarAnaIdx(CarAnaCarVo vo) throws Exception {
          List<BiCarIdxInfoEntity>  list =  PubUtil.convertListMapToObject(
              this.sqlMapDao.selectList("carAna.getCarAnaIdx", vo), BiCarIdxInfoEntity.class);
          return list;
     }
     
     /**
      * 查询排名
      * @return
      * @throws Exception
      * @author:lan
      * @email:763836737@qq.com
      */
      @SuppressWarnings("unchecked")
      public List<Map<String,Object>> getCarAnaRank(CarAnaCarVo vo) throws Exception {
          List<Map<String,Object>>  list =  this.sqlMapDao.selectList("carAna.getCarAnaRank", vo) ;
          return list;
      }
      
     /**
      * 趋势图
      * @param vo
      * @return
      * @throws Exception
      * @author:lan
      * @email:763836737@qq.com
      */
      @SuppressWarnings("unchecked")
      public List<Map<String,Object>> getCarAnaTrend(CarAnaCarVo vo) throws Exception {
    	  List<Map<String,Object>>  list = this.sqlMapDao.selectList("carAna.getCarAnaTrend", vo);
          return list;
      }
      
      /**
       * 查询能耗排名
       * @return
       * @throws Exception
       * @author:lan
       * @email:763836737@qq.com
       */
       @SuppressWarnings("unchecked")
       public List<Map<String,Object>> getCarAnaEnergyRank(CarAnaCarVo vo) throws Exception {
    	   List<Map<String,Object>>  list =  this.sqlMapDao.selectList("carAna.getCarAnaEnergyRank", vo) ;
           return list;
       }
       
     /**
      * 查询能耗转速分析
      * @return
      * @throws Exception
      * @author:lan
      * @email:763836737@qq.com
      */
      @SuppressWarnings("unchecked")
      public List<Map<String,Object>> getCarAnaEnergySpdAna(CarAnaCarVo vo) throws Exception {
    	  List<Map<String,Object>>  list =  this.sqlMapDao.selectList("carAna.getCarAnaEnergySpdAna", vo) ;
    	  return list;
     }
        
	/**
	 * 查询维保记录
	 * 
	 * @param dataVo
	 * @return
	 * @throws Exception
	 * @author:lan
	 * @email:763836737@qq.com
	 */
	@Transactional
	public Pagination searchMainteInfoPage(DrvAnaDrvVo timeVo) throws Exception {
		Pagination page = this.myBatisPage("carAna.getCarAnaMainteCnt","carAna.getCarAnaMainteList", timeVo, AppCarMaintenInfoEntity.class);
		Map<String, String> map2 = new HashMap<String, String>();
		map2.put("organName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo2 = new FillParamsVo("organId", map2);
		Map<String, String> map3 = new HashMap<String, String>();
		map3.put("lineName", GlobalConst.DEFAULT_CACHE_VALUE);
		FillParamsVo vo3 = new FillParamsVo("lineId", map3);
		Map<String,String> map4 = new HashMap<String,String>();
        map4.put("licPltNo", GlobalConst.DEFAULT_CACHE_VALUE);  
        FillParamsVo vo4 = new FillParamsVo("carId", map4);
		codeDscValue.fillInfoValue(page.getData(), new String[] {GlobalConst.CACHE_KEY_BASE_ORGAN,GlobalConst.CACHE_KEY_BASE_LINE_INFO,GlobalConst.CACHE_KEY_BASE_CAR_INFO},vo2,vo3,vo4);
		return page;
	}
        
	 /**
	  * 查询行车记录分析
	  * @param vo
	  * @return
	  * @throws Exception
	  */
     @SuppressWarnings({"unchecked"})
     public  List<DrivingRecordAnalysisVo> searchRecordAnalysisList(CarAnaCarVo vo)throws Exception {
          List<DrivingRecordAnalysisVo> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("carAna.searchRecordAnalysisList", vo), DrivingRecordAnalysisVo.class);
          return list;
      }
     
     /**
      * 查询行车记录分析图表
      * @param vo
      * @return
      * @throws Exception
      */
      @SuppressWarnings("unchecked")
	  @Transactional
      public  List<CommEnerConsStatInfoEntity> searchRecordAnalysisChart(CarAnaCarVo vo)throws Exception {
           List<CommEnerConsStatInfoEntity> list = PubUtil.convertListMapToObject(sqlMapDao.selectList("carAna.searchRecordAnalysisChart", vo), CommEnerConsStatInfoEntity.class);
           return list;
      }
}
